var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var MyUser = new Schema({
	id:Number,
	userkey:String,
	dashboard:Schema.Types.Mixed,
	modified:Date
}/*,{ minimize: false }*/);

//CRUD Operations
//Insert
/**
 * example:
 * var userid 	  = {id: 1};
 * var update     = {$set : {userkey : "linyanwen"}};
 * var options    = {upsert : true};
 * var callback   = function(error);
 */
MyUser.methods.Insert = function(userid, update, option, callback) {
	return this.model('users').update(userid, update, option, callback);
}

//Delete
/**
 * example:
 * var userid 	  = {id: 1};
 * var callback   = function(error);
 */
MyUser.methods.Delete = function(userid, callback) {
	return this.model('users').remove(userid, callback);
}

//Update
/**
 * example:
 * var userid 	  = {id: 1};
 * var update     = {$set : {userkey : "linyanwen"}};
 * var options    = {upsert : true};
 * var callback   = function(error);
 */
MyUser.methods.Update = function(userid, update, option, callback) {
	return this.model('users').update(userid, update, option, callback);
}

//Query
/**
 * example:
 * var userid 	  = {id: 1};
 * var callback   = function(error);
 */
MyUser.methods.Query = function(userid, callback) {
	return this.model('users').findOne(userid, callback);
}


//Static method
MyUser.statics.Insert = function(userid, update, option, callback) {
	return this.model('users').update(userid, update, option, callback);
}
MyUser.statics.Delete = function(userid, callback) {
	return this.model('users').remove(userid, callback);
}
MyUser.statics.Update = function(userid, update, option, callback) {
	return this.model('users').update(userid, update, option, callback);
}
MyUser.statics.Query = function(userid, callback) {
	return this.model('users').findOne(userid, callback);
}

exports.User=mongoose.model('users', MyUser);
